﻿package com.devilcat.ob {
	import flash.display.MovieClip ;
	import flash.events.Event;  
	import flash.display.Loader;
	import flash.net.URLRequest; 
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	import fl.transitions.TweenEvent; 
	import com.devilcat.dt.Gamedt;
	public class NPCPokemon extends MovieClip  {
		public var pokemonList:Array;
		public var eventLocation:String="";
		public var eventNumber:Number=0;
		public var destroy:Boolean;
		public var tweenList:Array = new Array();
		public function NPCPokemon(XMLData:XMLList){//imgPath:String,ps:Array,mb:Boolean=false){
			osuper(XMLData.img,true)
			if(XMLData.el!=null) eventLocation = XMLData.el;
			if(XMLData.en!=null) eventNumber = XMLData.en;			
			pokemonList=Gamedt.newWildPokemonList(XMLData.pkml);
/*			addEventListener(Event.ENTER_FRAME, alphaMe);
			function alphaMe(e:Event){
				//trace("Me");
				this.alpha =1;
				this.visible=true;
			}*/
			
//			Pokemon = new Array();
//			for(var i:int=0;i<XMLData.pkml.pkm.length;i++){
//				Pokemon.push(Gamedt.newWildPokemon(XMLData.pkml.child(i)));
//			}
		}
		public function osuper(imgPath:String, d:Boolean=false){
			loadIMG(imgPath);
			destroy=d;
			//this.addEventListener(Event.ENTER_FRAME, checkHit);			
		}
		function checkHit(e:Event){
		}
		private function loadIMG(imgPath:String) {
			var imageLoader:Loader = new Loader();
			var imageLink:URLRequest = new URLRequest("npc/"+imgPath+".png");
			imageLoader.load(imageLink);
			imageLoader.contentLoaderInfo.addEventListener(Event.INIT,imageLoaded);
			function imageLoaded(e:Event):void {
				addChild(imageLoader);
			}
		}
		public function addMe(){
			trace("Addme");
			//if(this.parent != null){
				this.parent.addChild(this);
				//trace ("Removed");
			//}
			tweenList.unshift(new Tween (this,"alpha",Strong.easeOut,0,1,2,true));
			tweenList.unshift(new Tween (this,"y",Strong.easeOut,this.y-50,this.y,2,true));
		}
		public function destroyTween(){
			trace("Destroy");
					//tweenList.unshift(new Tween (this,"alpha",Strong.easeOut,1,0,2,true));
					tweenList.unshift(new Tween (this,"scaleX",Strong.easeOut,1,2,2,true));
					tweenList.unshift(new Tween (this,"scaleY",Strong.easeOut,1,2,2,true));
					tweenList.unshift(new Tween (this,"y",Strong.easeOut,this.y,this.y-50,2,true));
					tweenList.unshift(new Tween (this,"x",Strong.easeOut,this.x,this.x+220,2,true));
					tweenList[0].addEventListener(TweenEvent.MOTION_FINISH,removeMe);
		}
		public function removeMe(e:Event){
			if(this.parent != null){
				this.parent.removeChild(this);
				//trace ("Removed");
			}
		}
		public function hitMe(){			
			if(destroy)destroyTween();
		}
		public function setEvent(el:String,en:Number){			
			if(el!=""){
				eventLocation=el;
				eventNumber=en;			
			}
		}
	}
}
	